package com.hdl.servlet.user;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hdl.service.UserService;
import com.hdl.service.impl.UserServiceImpl;

/**
 * 用户激活
 * @author Administrator
 *
 */
@WebServlet("/activeUserServlet")
public class ActiveUserServlet extends HttpServlet {
	
	private UserService service = new UserServiceImpl();
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//获取参数
		String code = req.getParameter("activeCode");
		
		//调用业务层激活
		int i = service.active(code);
		
		//转发 数据
		if(i == 1) {//成功
			req.setAttribute("msg", "用户已激活，请访问首页进行登陆");
		}else {
			req.setAttribute("error", "用户激活失败，请查看激活码是否正确");
		}
		
		req.getRequestDispatcher("/msg.jsp").forward(req, resp);
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}

}
